<?php
class ome_finder_refund_apply{
    var $detail_basic = "退款申请详情";

    function detail_basic($apply_id)
    {
        $render = app::get('ome')->render();
        $oRefund_apply = &app::get('ome')->model('refund_apply');
        $refunddatas = $oRefund_apply->refund_apply_detail($apply_id);
        $oObj= &app::get('ome')->model('orders');
        $render->pagedata['refunddata'] = $oRefund_apply->refund_apply_detail($apply_id);
        //根据订单号查询已退金额
        $oOrder = &app::get('ome')->model('orders');
        $orderinfo = $oOrder->order_detail($render->pagedata['refunddata']['order_id']);
        $oLoger = &app::get('ome')->model('operation_log');
        $render->pagedata['payed'] = $orderinfo['payinfo']['cost_payment'];
        if ($_POST)
        {   
        	$order_data = array(
        	   'order_id'=>$orderinfo['order_id'],
        	   'pause'=>'false',
        	);
        	$oOrder->save($order_data);
        	
            //验证原状态
            $data['apply_id'] = $apply_id;
            $apply_data = $oRefund_apply->refund_apply_detail($apply_id);
            $change_status = $_POST['status'];
            switch ($change_status)
            {
                case 1://未审核->审核中
                    if ($apply_data['status'] == 0)
                    {
                        $data['status'] = 1;
                        $order['pause'] = 'false';
                        //最近操作时间
                        $data['last_modified'] = time();
                        $oRefund_apply->save($data,true);
                        $oLoger->write_log('refund_verify@ome',$apply_id,"退款申请审核中");
                    }
                    break;
                case 2:
                case 3:
                    if ($change_status == 2)
                    {
                        $refund_op = 'refund_pass@ome';
                        $refund_op_name = '接受';
                    }
                    else {
                        $refund_op = 'refund_refuse@ome';
                        $refund_op_name = '拒绝';
                    }

                    if ($apply_data['status'] == 1)
                    {
                        $data['status'] = $change_status;
                        $data['last_modified'] = time();
                        $oRefund_apply->save($data,true);
                        $oLoger->write_log($refund_op,$apply_id,"退款申请 $refund_op_name");
						if($data['status'] == 3){
							//将订单状态还原
							kernel::single('ome_order_func')->update_order_pay_status($orderinfo['order_id']);
						}
                    }
                    break;
                default:
                    break;
                    //参数不正确，不进行任何更新。
            }
        }
        $render->pagedata['refunddata'] = $oRefund_apply->refund_apply_detail($apply_id);
        $render->pagedata['status_info'] = $render->pagedata['refunddata']['status'];
        $render->pagedata['log'] = $oLoger->read_log(array('obj_id'=>$apply_id,'obj_type'=>'refund_apply@ome'),0,-1);
        $render->pagedata['status_display'] = ome_refund_func::refund_apply_status();
        $render->pagedata['orderinfo'] = $orderinfo;
        $render->pagedata['finder_id'] = $_GET['finder_id'];
        return $render->fetch('admin/refund/refundapp_detail.html');
    }

}
?>
